<template>
  <BasicDrawer v-bind="$attrs" @register="register" title="PDF查看" width="60%" @open-change="handleVisibleChange">
    <div>
      <iframe :src="srcStr" frameborder="0" id="pdfFrame" ref="pdfFrame1" width="600px" height="600px"
        :style="styleObject"></iframe>
    </div>
    <a-row>
      <a-col :span="2">
        <a-button @click="accept()">接受</a-button></a-col>
      <a-col :span="2">
        <a-button @click="refuse()">不接受</a-button></a-col> 
      </a-row>
  </BasicDrawer>
</template>
<script lang="ts">
 import { defHttp } from '/@/utils/http/axios';
import { defineComponent, ref } from 'vue';
import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
import { getPDF } from '/@/utils/http/axios';
import {Button as AButton,  Row as ARow,  Col as ACol} from 'ant-design-vue';
enum Api {
  PDFS = '/pdf',
  ACCEPT="/pdfAccept",
  REFUSE="/pdfRefuse"
}
export default defineComponent({
 
  components: { BasicDrawer },
  setup() {
     
    let styleObject = ref("")
    let srcStr = ref("")

    async function openPdf(id:number) {
      const url: string =await getPDF(Api.PDFS,{id:id})
      srcStr.value = url;
      styleObject.value = "display:block"

    }

    function closePdf() {

      srcStr.value = "";
      styleObject.value = "display:none"

    }
    let pdfId=ref(0)
    const [register,{ closeDrawer }] = useDrawerInner((data) => {
       pdfId.value = data.id
          });
    function handleVisibleChange(visible) {
      if (visible) {
        openPdf(pdfId.value );
      }
      else {
        closePdf();
      }
    }
   
//接受与否
const PDFsituation  = (params: any = null,api:string="") => defHttp.get({ url: Api[api], params });
   async function accept() {
      await PDFsituation({id:pdfId.value},"ACCEPT");
     // 刷新页面
location.reload();
    }
    async function refuse() {
      await PDFsituation({id:pdfId.value},"REFUSE");
      closeDrawer();
    }
    return { register, openPdf, styleObject, srcStr, handleVisibleChange, refuse, accept,pdfId ,AButton,ARow,ACol};
  },
});
</script>
